import axios from 'axios'
import { MessageBox, Message } from 'element-ui'
import store from '@/store'
import { getToken } from '@/utils/auth'
import router from '@/router'

// create an axios instance
const service = axios.create({
  baseURL: "http://localhost:8080",
  //baseURL: "http://124.222.128.64:8080", // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

// request interceptor
service.interceptors.request.use(
  function (config) {
    config.headers.token = localStorage.getItem("token");
    return config;
  }
)

// response interceptor
service.interceptors.response.use(function(res){
  if(res.data.data=="403"){
    router.push("/403")
  }
  return res.data;
})

export default service
